package demo.practice.dp;

public class P84 {
    public static void main(String[] args) {
        P84 p84 = new P84();
        p84.largestRectangleArea(new int[]{2, 1, 5, 6, 2, 3});
    }

    public int largestRectangleArea(int[] heights) {
        int large = 0;
        for (int i = 0; i < heights.length; i++) {
            if (heights[i] == 0) {
                continue;
            }

            if (i - 1 >= 0  && heights[i] == heights[i - 1])
                continue;


            int w = 1;
            int h = heights[i];
            for (int k = i - 1; k >= 0; k--) {
                if (heights[k] >= heights[i]) {
                    w++;
                } else {
                    break;
                }
            }

            for (int k = i + 1; k < heights.length; k++) {
                if (heights[k] >= heights[i]) {
                    w++;
                } else {
                    break;
                }
            }
            large = Math.max(large, w * h);
        }

        return large;
    }
}
